home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / jpl_c.zip / MALLOC.C < prev    next >
Text File  |  1986-05-18  |  1KB  |  44 lines

  1. /* 1.4  02-11-86                         (malloc.c)
  2.  ************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1985, 86    *
  6.  ************************************************************************/
  7.  
  8. #include "defs.h"
  9. #include "stdtyp.h"
  10.  
  11. /************************************************************************/
  12.     char *
  13. malloc(nbytes)    /* Return pointer to block of memory nbytes in size, or
  14.            NULL if none available.                 */
  15. /*----------------------------------------------------------------------*/
  16. FAST unsigned nbytes;
  17. {
  18.     char *allot();
  19.     FAST HEADER *p;
  20.     unsigned n_units();
  21.  
  22.     nbytes = (1 + n_units(nbytes)) * sizeof(HEADER);
  23.     if (p = (HEADER *)allot(nbytes)) /* round up to align, allocate.*/
  24.     {    p->s.size = nbytes;    /* size field in bytes.        */
  25.         p++;
  26.     }
  27.     return (char *) p;
  28. }
  29.  
  30. /************************************************************************/
  31.     VOID
  32. free(ap)        /* put block ap in free memory list.        */
  33.  
  34. /*----------------------------------------------------------------------*/
  35. char *ap;
  36. {
  37.     FAST HEADER *p;
  38.  
  39.     if (p)
  40.     {    p = (HEADER *) ap - 1; /* at header left there by malloc() */
  41.         liberate(p, p->s.size);
  42.     }
  43. }
  44.